package com.creative.util;

import android.content.Context;
import org.json.JSONArray;
import java.io.InputStream;

/**
 * 将从主app中下发的区域数据 序列化到本地 area.json中，再将 main app asset中取
 * Created by david on 15/11/26.
 */
public class JsonFileUtils {

    public static JSONArray json(Context context) {
        JSONArray array =null;
        try {
            //将json文件读取到buffer数组中
            InputStream is = context.getResources().getAssets().open("area.json");
            byte[] buffer = new byte[is.available()];
            is.read(buffer);
            //将字节数组转换为以GB2312编码的字符串
            String json = new String(buffer);
            //将字符串json转换为json对象，以便于取出数据
            array = new JSONArray(json);
        } catch (Exception e) {
           e.printStackTrace();
        }
        return array;
    }
}
